:- source.
:- use_module(library(lists)).
:- style_check(all).
:- yap_flag(unknown,error).

init_marks_c([],[]).
init_marks_c([_Offset - _I|Rest],[MarkedCodePoint|MarkedCodePoints]):-
	MarkedCodePoint = 'Unmarked',
	init_marks_c(Rest,MarkedCodePoints).

initialize_marklist([],[]).
initialize_marklist([M|MethodBodies],[(Method-MarkedC)|MarkedCs]) :-
	M =..  [method_body, Method, _MS, _LC, _ISD,
       		_MSD, _CL, C, _EC, _E, _TC, _T],
	init_marks_c(C,MarkedC),
	initialize_marklist(MethodBodies,MarkedCs).


print_marklists([(Method-MarkedC)|MarkedCs]) :-
	write('Method: '), writeln(Method),
	print_marklist(MarkedC),
	write('\n'),
	print_marklists(MarkedCs).
print_marklists([]).
print_marklist([MarkedCodePoint|MarkedCodePoints]):-
	writeln(MarkedCodePoint),
	print_marklist(MarkedCodePoints).
print_marklist([]).

%given a methodnum and an instruction offset, find out if that
%instruction is marked

get_marked_method(MC, [M | _], M) :-
	M =.. [method_body,MC,_MS1,_LC1,_ISD1,_MSD1,_CL1,_NInsList,_EC1,_E1,_TC1,_T1].
get_marked_method(MC, [M | MT], MF) :-
	get_marked_method(MC, MT, MF).

find_marking(MethodNum,(Offset - I),MarkedCs,Marking) :-
	nth0(MethodNum,MarkedCs,MarkedC),
	select((Offset - I,Marking),MarkedC,_Rest).
	
